#include "rules_searcher.hpp"

namespace mashine { namespace kb { namespace search {

/**
 * create visitor that search facts with specified name
 * by default name = * (select all facts)
 */
RulesSearchVisitor::RulesSearchVisitor(mashine::kb::Literal l)
		: SearchVisitor<mashine::kb::Rule *, mashine::kb::Literal>(l)
{

}

/**
 * get array of facts selected from kBase
 */
std::vector<mashine::kb::Rule *> RulesSearchVisitor::search(mashine::kb::KnowledgeBase * kBase)
{
	std::vector<mashine::kb::Rule *> result;

	std::vector<mashine::kb::Rule>::const_iterator i;
	for (i = kBase->getRules().begin(); i != kBase->getRules().end(); ++i)
	{
		APP_LOGGER(info) << criteria.toString() << " : " << (*i).getUndeniableLiteral();
		if (criteria == *((*i).getUndeniableLiteral()) )
		{
			result.push_back(const_cast<mashine::kb::Rule *>(&(*i)));
		}
	}

	return result;
}

}}}
